<?php
$arr = array();
header('Content-Type: text/html; charset=utf-8');
setlocale(LC_ALL, 'ar_LB');
require_once 'Excel/reader.php';
  //ExcelFile($filename, $encoding);
$data = new Spreadsheet_Excel_Reader();
print_r($_REQUEST);
// Set output Encoding.
$data->setOutputEncoding('CP1251');
   if($_REQUEST['click_on']=='Upload'){
 	 $file = $_FILES['dd_file']['name'];
	 echo $_FILES['dd_file']['type'];
  	if($_FILES['dd_file']['name']==""){
  		$Error = "<font color=red>Please browse for the file to be uploaded.</font>";
 	}elseif($_FILES['dd_file']['type']!="application/vnd.ms-excel" and $_FILES['dd_file']['type']!="application/octet-stream" and $_FILES['dd_file']['type']!="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ){
 		echo $Error = "<font color=red>Please locate files only in CSV format.</font>";
 	}else{ 
  			$file = mt_rand(1,1000).$file;
 			if(move_uploaded_file($_FILES['dd_file']['tmp_name'],"CSVUPLOADER/".$file)) {

 				echo $data->read("CSVUPLOADER/".$file);

				error_reporting(E_ALL ^ E_NOTICE);
 				for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
				if($data->sheets[0]['cells'][$i][1]){
 					 				//print_r(get_html_translation_table($data->sheets[0]['cells'][$i][2]));
									//echo $newcode;
 								//	echo "<br><br><br><br><br><br>";
					}
				if($data->sheets[0]['cells'][$i][1]){
				 $sql = "INSERT INTO tbl_product set  category_id = '".addslashes($data->sheets[0]['cells'][$i][1])."', product_code = '".addslashes($data->sheets[0]['cells'][$i][2])."', product_name = '".addslashes($data->sheets[0]['cells'][$i][3])."', product_description = '".addslashes($data->sheets[0]['cells'][$i][4])."', quantity = '".addslashes($data->sheets[0]['cells'][$i][5])."', product_price = '".addslashes($data->sheets[0]['cells'][$i][6])."'"; 
				 
  					  //  echo $sql."<br><br><br>";
					  mysql_query($sql) or die("Error-".mysql_error());
				$pro_id	= mysql_insert_id();
				$sqlImage="insert into tbl_product_images SET product_id='$pro_id', product_type='p',product_image_1='".addslashes($data->sheets[0]['cells'][$i][7])."',product_image_2='".addslashes($data->sheets[0]['cells'][$i][8])."',product_image_3='".addslashes($data->sheets[0]['cells'][$i][9])."',product_image_4='".addslashes($data->sheets[0]['cells'][$i][10])."',product_image_5='".addslashes($data->sheets[0]['cells'][$i][11])."'";
				mysql_query($sqlImage);
}
	}	
		}
					$Msg = 1;
			 	unlink("CSVUPLOADER/".$file);
		}

  }
 

///////////////////////////////////////////////////////////// 
?>
<form action="" onsubmit=" return chkphoto();"" method="post" enctype="multipart/form-data" name="formUpload" id="formUpload">
  <table width="100%" border="0">
    <tr>
      <td height="30" colspan="2"><strong>Multiple uploading product</strong></td>
    </tr>
    <tr>
      <td width="27%">Upload csv file</td>
      <td width="73%"><label>
        <input type="file" name="dd_file" id="dd_file">
      <input name="click_on" type="submit" class="button1" id="click_on"  value="Upload" /></label></td>
    </tr>
    <tr>
      <td>Upload image</td>
      <td><label>
        <div id="sampleFile">
<?php include_once('uploadify-multi-single.php'); ?>
</div>
      </label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>
        <input type="submit" name="button" id="button" value="Submit">
      </label></td>
    </tr>
  </table>
  <input type="hidden" name="folder" id="photofolder" value="<?php echo $photo_row['photo_id'];?>">
</form>
